import { Router } from 'vue-router'
import { useLoginUserStore } from 'store/modules/LoginUserStore'
import { isLogin } from 'utils/SystemUtil'

/**
 * 安装：获取当前登录用户信息的路由守卫(如果当前登录用户信息为null,则从后台获取登录用户信息)
 * @param router
 */
export function installLoadLoginUserDataGuard(router: Router) {
  router.beforeEach(async (to, from) => {
    console.log('loadLoginUserDataGuard', 'to', to, 'from', from)
    const loginUserStore = useLoginUserStore()
    if (isLogin()) {
      await loginUserStore.doLoadLoginUserInfo()
    }
    return true
  })
}
